<?php
/**
 * Created by PhpStorm.
 * User: 秋刀鱼
 * Date: 2018/6/7
 * Time: 9:57
 */

namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use \common\helps\tools;//使用工具类
use yii\web\models;
use yii\db\Connection;
/**
 * Site controller
 */
class InfoController extends Controller
{


    public function init()
    {
        $this->enableCsrfValidation = false;
    }

    /**
     * title 消息列表
     *
     * @return string
     */
    public function actionList()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['id'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken($uid,$token);
        if($checkToken != 4){
            return tools::ajax_return('9','token过期,请重新登录',[$checkToken]);
        }

        $info = new \app\models\NewInfo;
        $list = $info->fiveInfo($uid);
        if($list){
            return tools::ajax_return('0','成功',$list);
        }else{
            return tools::ajax_return_error('1','失败',[]);
        }

    }


    /**
     * title 全部消息列表
     *
     * @return string
     */
    public function actionTotallist()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['id'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken($uid,$token);
        if($checkToken != 4){
            return tools::ajax_return('9','token过期,请重新登录',[$checkToken]);
        }

        $info = new \app\models\NewInfo;
        $list = $info->selectInfo($uid);
        if($list){
            return tools::ajax_return('0','成功',$list);
        }else{
            return tools::ajax_return_error('1','失败',[]);
        }

    }




    /**
     * title 详情
     * @return string
     */
    public function actionDetailsinfo(){
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['id'];
        $token = $post['token'];
        $infoId = $post['infoId'];
        //token验证
        $checkToken = tools::checkToken($uid,$token);
        if($checkToken != 4){
            return tools::ajax_return('9','token过期,请重新登录',[$checkToken]);
        }

        $info = new \app\models\NewInfo;
        $details = $info->detailInfo($infoId);
        if($details == 2){
            return tools::ajax_return_error('1','失败',[]);
        }

        return tools::ajax_return('0','成功',$details);


    }


    /**
     * title email标志
     * @return string
     */
    public function actionEmailFlag()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['uid'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken($uid,$token);
        if($checkToken != 4){
            return tools::ajax_return('9','token过期,请重新登录',[$checkToken]);
        }

        $info = new \app\models\NewInfo;
        $details = $info->emailFlag($uid);
        if($details == 3){
            return tools::ajax_return('3','成功',['有未读']);
        }else if($details == 2){
            return tools::ajax_return('0','成功',[]);
        }else{
            return tools::ajax_return('1','失败',[]);
        }


    }




}
